package com.gxuwz.volunteer.mapper;

import com.gxuwz.volunteer.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {

    // 获取用户信息
    @Select("SELECT * FROM user WHERE user_id = #{userId}")
    User getUserProfile(Integer userId);

    // 更新用户信息
    @Update("UPDATE user SET name = #{name}, class = #{className}, department = #{department}, " +
            "phone = #{phone}, email = #{email}, password = #{password}, role = #{role} WHERE user_id = #{userId}")
    void updateUserProfile(Integer userId, User user);

    // 获取用户统计数据
    @Select("SELECT COUNT(*) FROM user WHERE user_id = #{userId}")
    String getUserStats(Integer userId);

    // 获取用户活动记录
    @Select("SELECT activity_name FROM activities WHERE user_id = #{userId} AND activity_status = #{params}")
    List<String> getUserActivities(Integer userId, String params);

    // 获取用户列表（管理员使用）
    @Select("SELECT * FROM user WHERE role = #{role}")
    List<User> getUsers(String role);

    // 创建用户（管理员使用）
    @Insert("INSERT INTO user (name, class, department, phone, email, password, role) " +
            "VALUES (#{name}, #{className}, #{department}, #{phone}, #{email}, #{password}, #{role})")
    void createUser(User user);

    // 删除用户（管理员使用）
    @Delete("DELETE FROM user WHERE user_id = #{userId}")
    void deleteUser(Integer userId);
}
